function getPath(){
	var strFullPath=window.document.location.href;  
    var strPath=window.document.location.pathname;  
    var pos=strFullPath.indexOf(strPath);  
    var prePath=strFullPath.substring(0,pos);  
    var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);  
    var basePath = prePath;  
    basePath = prePath + postPath;
    return basePath;
}
function getPrePath(){
	var strFullPath=window.document.location.href;  
    var strPath=window.document.location.pathname;  
    var pos=strFullPath.indexOf(strPath);  
    var prePath=strFullPath.substring(0,pos);  
    var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);  
    var basePath = prePath;  
    return basePath;
}
var debug = true;
var serverUrl=getPath();
var qrcodeUrl="http://www.shinehao.net/weixin/weiXin/sh?orderId=";
var imgUrl = getPrePath();
var isChrome = navigator.userAgent.toLowerCase().match(/chrome/) != null;
if(!isChrome){
    $('#dialogforsysinfo').dialogBox({
            type: 'error',  //three type:'normal'(default),'correct','error',
            width: 300,
            height: 300,
            hasMask: true,
            autoHide: true,
            hasClose:true,
            time: 3000,
            effect: 'fall',//fall
            title: '提醒',
            content: "为了提高软件使用体验,请使用谷歌Chrome浏览器,3秒之后跳转Chrome下载页,即将关闭此页面"
        });
    setTimeout(function(){
    			newWinNoRepeat("https://img.binlife.net/69.0.3497.92_chrome_installer.exe","getChrome"); 
                window.close();
 			},3000)
    
}

var basicDataFixed={
    username:"",
    company:"",
    order_no:"",
    is_update:"",//1只能下拉选择
    init:function(){
        $.ajax({
              type: 'POST',
              url: serverUrl+"/createOrder/getOrderInfoFixed",
              data: {},
              success: function(data){
               if(!data.result){
                   show_error_dialog(data.info);
                   return;
               }
               console.info(data.data[0].result);
               console.info(data.data[1].loginCompany);
               basicDataFixed.order_no = data.data[0].result;
               basicDataFixed.company  = data.data[1].loginCompany;
               basicDataFixed.username  = data.data[1].loginUserName;
               basicDataFixed.isUpdate  = data.data[2].isUpdate;
              },
              dataType: "json"
            });
    }
}
basicDataFixed.init();
/*if(window.location.href.indexOf("template.html")>-1){
   myformUtils.formClearAll("#myformsubmit","order_");
   basic_index.template_id=localStorage.getItem("template_id");
}*/

//动态添加订单编号
if($("[name='order_p_order_no']").length==0){
	$("#myformsubmit").prepend('<input type="text" name="order_p_order_no" readonly="readonly" hidden>')
}
//小工具
var menubuttonIndexTool={
	interval_saveOrderInfo:'',
	saveAsimg:function(){
		$.getScript("./jquery/html2img/html2cavas.min.js")
		 .done(function() {
			 $.getScript("./jquery/html2img/canvas2image.js")
			 .done(function() {
				 html2canvas(document.querySelector(".right")).then(canvas => {
						//console.info(canvas.toDataURL("image/webp", "1.0")); 
					    Canvas2Image.saveAsImage(canvas, canvas.width, canvas.height, 'jpeg',basicDataFixed.company+"-"+$("[name='order_p_order_no']").val());
					});
			});
		});
	},
	//获取rightbase64img
	saveAsBase64img:function(){
		/*$.getScript("./jquery/html2img/html2cavas.min.js")
		 .done(function() {
			 $.getScript("./jquery/html2img/canvas2image.js")
			 .done(function() {
				 html2canvas(document.querySelector(".right")).then(canvas => {
						console.info(canvas.toDataURL("image/jpeg", "1.0")); 
						menubuttonIndexTool.saveAsBase64imgAjax(canvas.toDataURL("image/jpeg", "1.0"));
					});
			});
		});*/
		html2canvas(document.querySelector(".right")).then(canvas => {
			console.info(canvas.toDataURL("image/jpeg", "1.0")); 
			menubuttonIndexTool.saveAsBase64imgAjax(canvas.toDataURL("image/jpeg", "1.0"));
		});
	},
	//base64 img保存于服务器
	saveAsBase64imgAjax:function(base64img){
		$.ajax({
	        type: 'POST',
	        url: serverUrl+"/fileManager/uploadFileByBase64",
	        data: {base64content:base64img,order_no:$("[name='order_p_order_no']").val(),type:1},
	        success: function(data){
	          console.info(data);
	          console.info("menubuttonIndexTool.saveAsBase64imgAjax success");
	          //董良福外部刷新订单图片内容
	          var iframeParent = window.parent;
              if (iframeParent === null || iframeParent === undefined) {
                return;
              }
              var fun = iframeParent.trggerEvent;
              if (fun !== undefined) {
                fun('update-complete', [data]);
              }
	        }
		});
	},
	//template.html新增订单实时保存数据
	saveTemplateDataAsFile:function(){
		if(window.location.href.indexOf("template.html")>-1&&window.location.href.indexOf("order_no")<0){
			var data=myformUtils.formToArrByAllNames("#myformsubmit","order_");
			var time = utilgetFormatDate("yyyy-MM-dd HH:mm:SS");
			$.getScript("./jquery/html5file/FileSaver20141129.js")
			 .done(function() {
				 var blob = new Blob([JSON.stringify(data)], {type: "text/plain;charset=utf-8"});
				 saveAs(blob, time+"-订单.json");
				 /*$.messager.show({
			            title:'提示',
			            msg:'自动保存成功下载完毕,文件名['+time+"-订单.json]",
			            timeout:1000,
			            showType:'slide',
			            style:{
		                    right:'',
		                    bottom:''
		                }
			     });*/
			});
		}
	},
	//template.html新增订单实时保存数据
	saveTemplateDataAsFileNow:function(){
		if(window.location.href.indexOf("template.html")>-1){
			var data=myformUtils.formToArrByAllNames("#myformsubmit","order_");
			var time = utilgetFormatDate("yyyy-MM-dd HH:mm:SS");
			$.getScript("./jquery/html5file/FileSaver20141129.js")
			 .done(function() {
				 var blob = new Blob([JSON.stringify(data)], {type: "text/plain;charset=utf-8"});
				 saveAs(blob, time+"-订单.json");
				 /*$.messager.show({
			            title:'提示',
			            msg:'自动保存成功下载完毕,文件名['+time+"-订单.json]",
			            timeout:1000,
			            showType:'slide',
			            style:{
		                    right:'',
		                    bottom:''
		                }
			     });*/
			});
		}
	},
	//禁止自动保存
	clear_interval_saveOrderInfo:function(){
		clearInterval(menubuttonIndexTool.interval_saveOrderInfo);
		$.messager.show({
            title:'提示',
            msg:'已禁止自动保存',
            timeout:2000,
            showType:'slide',
        	style:{
                right:'',
                bottom:''
            }
        });
	},
	//启用自动保存
	start_interval_saveOrderInfo:function(){
		//每三分钟保存本地文件
		clearInterval(menubuttonIndexTool.interval_saveOrderInfo);
		menubuttonIndexTool.interval_saveOrderInfo = setInterval(function(){menubuttonIndexTool.saveTemplateDataAsFile()},180000);
	},
	//载入订单json数据
	loadOrderInfo:function(){
		var selectedFile = document.getElementById("file_loadOrderInfojson").files[0];//获取读取的File对象
	    var name = selectedFile.name;//读取选中文件的文件名
	    var size = selectedFile.size;//读取选中文件的大小
	    console.log("文件名:"+name+"大小："+size);
	    var reader = new FileReader();//这里是核心！！！读取操作就是由它完成的。
	    reader.readAsText(selectedFile);//读取文件的内容
	    reader.onload = function(){
	        console.log(this.result);//当读取完成之后会回调这个函数，然后此时文件的内容存储到了result中。直接操作即可。
	        myformUtils.formFillByJson("#myformsubmit","order_",JSON.parse(this.result));
	    };
	    var file = document.getElementById("file_loadOrderInfojson");
	    // for IE, Opera, Safari, Chrome
        if (file.outerHTML) {
            file.outerHTML = file.outerHTML;
        } else { // FF(包括3.5)
            file.value = "";
        }
	},
	//初始就启动
	initStart:function(){
		setTimeout(function(){menubuttonIndexTool.start_interval_saveOrderInfo();menubuttonIndexTool.fixcontenxtmenu();},5000);
	},
	//间接触发file按钮功能
	triggle_file_loadOrderInfojson:function(){
		$("#file_loadOrderInfojson").click();
	},
	//字体修改大小
	fontsizeset:function(){
		var fontsize_str=
			`<div style='height:10px'></div>
			<div style='height:70px'>
				<input type="checkbox" id="fontsize_checkbox" checked value="order" />订单信息
			    <input type="checkbox" id="fontsize_checkbox" checked value="material" />物料仓
			    <input type="checkbox" id="fontsize_checkbox" checked value="bigmaterial" />物料大组件
			    <input type="checkbox" id="fontsize_checkbox" checked value="tag" />自定义标签
			    </br><input type="checkbox" id="fontsize_checkbox" value="print" />打印表头名
			</div>
			<input class="easyui-slider" value="16" style="width:250px" data-options="
            showTip: true,
            min:10,
            max:50,
            rule: [10,'|',20,'|',30,'|',40,'|',50],
            tipFormatter: function(value){
                return value+'px';
            },
            onChange: function(value){
            	menubuttonIndexTool.fontsizeChange(value);
            }">
            <div style="height:60px"> </div>
            <div style="">
				内容位置调整:
				<select id="mytextAlign" onchange="menubuttonIndexTool.textAlignChange()">
					<option value="请选择">请选择</option>
					<option value="left">居左</option>
					<option value="center">居中</option>
				</select>
			</div>
            <div style='height:30px'></div>
            <h5 style="color:red">温馨提示:</br>完善订单后,最后操作字体大小调整,保存订单.</h5>`;
		$('div#easyui_dialog_index').dialog({
            modal: true,
            title: '字体大小设置',
            width: "350",
            height: "300",
            closed: false,
            border:true,
            cache: false,
            content:fontsize_str,
            onClose : function() {  
               $("div#easyui_dialog_index").dialog('destroy');  
               $("body").append("<div id='easyui_dialog_index'></div>");
            }
        });
	},//字体大小改变的时候
	fontsizeChange:function(val){
		//source_factory_colresizeable_for_two??
		 $("[id='fontsize_checkbox']").each(function(){
             if($(this).is(":checked")){
            	 /*console.info($(this).val());*/
            	 if($(this).val()=="order"){
            		 $("[id^='draggable_order_info_']").each(function(){
            			 $(this).find(".right-div-comp-left-text-span").css({"font-size":val+"px","line-height":(val+2)+"px"})
            			 $(this).find("[name]").css({"font-size":val+"px","line-height":(val+2)+"px"})
            		 })
            	 }
            	 if($(this).val()=="material"){
            		 $("[id^='draggable_source_factory_']").each(function(){
            			 if($(this).find(".source_factory_colresizeable").length<1){
            				 $(this).find(".right-div-comp-left-text-span").css({"font-size":val+"px","line-height":(val+2)+"px"})
                			 $(this).find("[name]").css({"font-size":val+"px","line-height":(val+2)+"px"})
            			 }
            			 //物料大组件
            			 //$(this).find(".source_factory_colresizeable_td_div").css({"font-size":val+"px","line-height":val+"px"})
            		 })
            		 $("[id^='draggable_second_factory_']").each(function(){
            			 $(this).find(".right-div-comp-left-text-span").css({"font-size":val+"px","line-height":(val+2)+"px"})
            			 $(this).find("[name]").css({"font-size":val+"px","line-height":(val+2)+"px"})
            		 })
            		 $("[id^='draggable_info_remark_factory_']").each(function(){
            			 $(this).find(".right-div-comp-left-text-span").css({"font-size":val+"px","line-height":(val+2)+"px"})
            			 $(this).find("[name]").css({"font-size":val+"px","line-height":(val+2)+"px"})
            		 })
            	 }
            	 if($(this).val()=="bigmaterial"){
            		//物料大组件
            		 $("[id^='draggable_source_factory_']").each(function(){
            			 if($(this).find(".source_factory_colresizeable").length>0){
                			 $(".source_factory_colresizeable").find(".source_factory_colresizeable_td_div").css({"font-size":val+"px","line-height":(val+2)+"px"})
            			 }
            			 if($(this).find(".source_factory_colresizeable_for_two").length>0){
                			 $(".source_factory_colresizeable_for_two").find(".source_factory_colresizeable_td_div").css({"font-size":val+"px","line-height":(val+2)+"px"})
            			 }
            		 });
            	 }
            	 if($(this).val()=="tag"){
            		 $("[id^='draggable_label_']").each(function(){
            			 $(this).find("[name]").css({"font-size":val+"px","line-height":(val+2)+"px"})
            		 })
            	 }
            	 if($(this).val()=="print"){
            		 $("#jprint_area").attr("print-font",val);
            	 }
             }
         });
	},
	//位置显示事件
	textAlignChange:function(){
		var text_align = $("#mytextAlign").val();
		if(text_align!="请选择"){
			$("[id='fontsize_checkbox']").each(function(){
	             if($(this).is(":checked")){
	            	 /*console.info($(this).val());*/
	            	 if($(this).val()=="order"){
	            		 $("[id^='draggable_order_info_']").each(function(){
	            			 $(this).find(".right-div-comp-left-text-span").css({"text-align":text_align})
	            			 $(this).find("[name]").css({"text-align":text_align})
	            		 })
	            	 }
	            	 if($(this).val()=="material"){
	            		 $("[id^='draggable_source_factory_']").each(function(){
	            			 if($(this).find(".source_factory_colresizeable").length<1){
	            				 $(this).find(".right-div-comp-left-text-span").css({"text-align":text_align})
	                			 $(this).find("[name]").css({"text-align":text_align})
	            			 }
	            			 //物料大组件
	            			 //$(this).find(".source_factory_colresizeable_td_div").css({"font-size":val+"px","line-height":val+"px"})
	            		 })
	            		 $("[id^='draggable_second_factory_']").each(function(){
	            			 $(this).find(".right-div-comp-left-text-span").css({"text-align":text_align})
	            			 $(this).find("[name]").css({"text-align":text_align})
	            		 })
	            		 $("[id^='draggable_info_remark_factory_']").each(function(){
	            			 $(this).find(".right-div-comp-left-text-span").css({"text-align":text_align})
	            			 $(this).find("[name]").css({"text-align":text_align})
	            		 })
	            	 }
	            	 if($(this).val()=="bigmaterial"){
	            		//物料大组件
	            		 $("[id^='draggable_source_factory_']").each(function(){
	            			 if($(this).find(".source_factory_colresizeable").length>0){
	                			 $(this).find(".source_factory_colresizeable_td_div").css({"justify-content":text_align})
	            			 }
	            		 });
	            	 }
	            	 if($(this).val()=="tag"){
	            		 $("[id^='draggable_label_']").each(function(){
	            			 $(this).find("[name]").css({"text-align":text_align})
	            		 })
	            	 }
	             }
	         });
		}
	},
	//清除NAME逗号判断
	clear_Interval_UtilForEveryAreaEvent_allNameReplaceDH:function(){
		clearInterval(Interval_UtilForEveryAreaEvent_allNameReplaceDH);
	},
	//订单附件上传
	uploadOrderFile:function(){
		var orderNo = $("[name='order_p_order_no']").val();
		$('div#easyui_dialog_index').dialog({
            modal: true,
            title: '订单附件上传',
            width: "500",
            height: "400",
            closed: false,
            border:true,
            cache: false,
            content:"<iframe frameborder='0' scrolling='no' style='width:99%;height:97%;' src='uploadOrderFile.html?type=2&orderNo="+orderNo+"'></iframe>",
            onClose : function() {  
               $("div#easyui_dialog_index").dialog('destroy');  
               $("body").append("<div id='easyui_dialog_index'></div>");
            }
        });
	},
	//添加物料类型
	addMaterialType:function(){
		$('div#easyui_dialog_index').dialog({
            modal: true,
            title: '物料类型添加',
            width: "500",
            height: "400",
            closed: false,
            border:true,
            cache: false,
            content:"<iframe frameborder='0' scrolling='no' style='width:99%;height:97%;' src='addMaterialType.html'></iframe>",
            onClose : function() {  
               $("div#easyui_dialog_index").dialog('destroy');  
               $("body").append("<div id='easyui_dialog_index'></div>");
            }
        });
	},
	//通过业务单数据载入到生产订单模版
	loadDataFromBusiness:function(){
		$('div#easyui_dialog_index').dialog({
            modal: true,
            title: '物料类型添加',
            width: "500",
            height: "400",
            closed: false,
            border:true,
            cache: false,
            content:"<iframe frameborder='0' scrolling='no' style='width:99%;height:97%;' src='select_template_data_from_ywd.html'></iframe>",
            onClose : function() {  
               $("div#easyui_dialog_index").dialog('destroy');  
               $("body").append("<div id='easyui_dialog_index'></div>");
            }
        });
	},
	//物料大组件刷新
	refreshMaterialTable:function(){
		if($(".source_factory_colresizeable").length>0){
			$(".source_factory_colresizeable").colResizable({
	    		liveDrag:true, 
	    		postbackSafe:true,
	    		partialRefresh:true,
	    		minWidth:20
	    	});
			$(".source_factory_colresizeable").parent().find(".JCLRgrips").not(":last").remove();
		}
		//source_factory_colresizeable_for_two
		if($(".source_factory_colresizeable_for_two").length>0){
			$(".source_factory_colresizeable_for_two").colResizable({
	    		liveDrag:true, 
	    		postbackSafe:true,
	    		partialRefresh:true,
	    		minWidth:20
	    	});
			$(".source_factory_colresizeable_for_two").parent().find(".JCLRgrips").not(":last").remove();
		}
		
	},
	//制单尺寸选择
	createOrderSize:function(str){
		switch(str)
		{
		case 'a3x':
			newWinNoRepeat("./a3_index_x.html");
		  break;
		case 'a3y':
			newWinNoRepeat("./a3_index_y.html");
		  break;
		case 'a4x':
			newWinNoRepeat("./index_x.html");
		  break;
		case 'a4y':
			newWinNoRepeat("./index_y.html");
		  break;
		default:
		  alert("制单尺寸选择出错,请联系平台工作人员")
		}
		
	},
	//修改右键contextmenu
	fixcontenxtmenu:function(){
		$("#context-menu-layer").remove();
		$(".draggable").removeClass("context-menu-active");
		$(".context-menu-list").hide()
	},
	//组件样式1 5 6 7不能移动修正
	mydraggablehandler_move:function(){
		$(".mydraggablehandler").each(function(){
			$(this).css ("left", $(this).parent().position().left);
		})
		mydraggablehandler();
	},
	buildRegex(regtext) {
		var op = "gi";
		/*if (document.getElementById("optionGlobal").checked)op = "g";
		if (document.getElementById("optionIgnoreCase").checked)op = op + "i";*/
		return new RegExp(regtext,op);
	},
	//正则匹配
	//\\d{1,4}((\\.)?\\d)\\*\\d{1,4}((\\.)?\\d?)\\*\\d{1,4}((\\.)?\\d?)
	onMatch(content,regtext) {
		console.info(regtext);
		var regex = this.buildRegex(regtext);
		var result = content.match(regex);
		if (null==result || 0==result.length) {
			return "";
			//return false;
		}
		/*if (document.getElementById("optionGlobal").checked) {
			var strResult = "共找到 " + result.length + " 处匹配：\r\n";
			for (var i=0;i < result.length;++i)strResult = strResult + result[i] + "\r\n";
			document.getElementById("textMatchResult").value = strResult;
		}
		else {
			document.getElementById("textMatchResult").value= "匹配位置：" + regex.lastIndex + "\r\n匹配结果：" + result[0];
		}*/
		var strResult="";
		for (var i=0;i < result.length;++i)strResult = strResult + result[i];
		
		return strResult;
	},
	/*计算日志*/
	calResultForMTLKKSLog:"",
	/*计算每条可开料数*/
	cal_order_s_mtlkt_total:function(){
		//日志清空
		menubuttonIndexTool.calResultForMTLKKSLog="";//"温馨提示:物料计算功能仅限 板材圈,板材肶<br>";
		
		//多个物料组件
		for(var iIndex=0;iIndex<2;iIndex++){
			//查询模板上 开料尺寸,板料规格型号 并且物料类型是板材圈和板材肶
			var cols = eval(basic_index.getSaveTemplateInfoData()[(iIndex==0)?"order_s_table_source_arr_str":"order_s_table_source_arr_str_for_two"]);//每个下面对应几列分别是什么
			var materialTypes = (iIndex==0)?tbsourcefactoryColresizeEvent.table_source_type_arr():tbsourcefactoryColresizeEventForTwo.table_source_type_arr();//物料类型
			
			if(cols==undefined){
				continue;
			}
			//满足含有 规格型号 开料方式  开料尺寸
			for(var i=0;i<cols.length;i++){
				if(cols[i].indexOf("order_s_material_model")>-1//规格型号
					&&cols[i].indexOf("order_s_klfs_way")>-1//开料方式
					&&cols[i].indexOf("order_s_klcc_size")>-1//开料尺寸
					&&cols[i].indexOf("order_s_mtlkt_total")>-1//每条料可开数
					)
				{
					console.info(materialTypes[i]);
					//物料必须是板材圈,板材肶
					/*不限制物料类型*/
					//if("板材圈"==materialTypes[i]||"板材肶"==materialTypes[i]){
						//通过物料类型拿到其父节点td 的 uniqueid
						var uniqueid = 
							(iIndex==0)?$(".source_factory_colresizeable").find("[name='order_s_material_type']").eq(i).parent().attr("uniqueid"):$(".source_factory_colresizeable_for_two").find("[name='order_s_material_type']").eq(i).parent().attr("uniqueid");
						console.info(uniqueid);
						menubuttonIndexTool.getDate_calOrderSMtlktTotal(uniqueid,materialTypes[i]);
					//}else{
						//menubuttonIndexTool.calResultForMTLKKSLog += "物料类型限制为[板材圈][板材肶]\r\n<br>";
					//}
				}
			}
		}
		
		$('#dialogforsysinfo').dialogBox({
            type: 'normal',  //three type:'normal'(default),'correct','error',
            width: 400,
            height: 300,
            hasMask: true,
            //autoHide: true,
            hasClose:true,
            //time: 3000,
            effect: 'fall',//fall
            title: '提醒-计算日志',
            content: menubuttonIndexTool.calResultForMTLKKSLog
        });
	},
	//通过物料类型和uniqueid获取 规格型号 开料方式 开料尺寸 计算每条料可开数
	getDate_calOrderSMtlktTotal:function(uniqueidStr,materialTypeStr){
		//获取每行的 规格型号 开料方式 开料尺寸
		$("[uniqueid='"+uniqueidStr+"']").find("[name='order_s_material_model']").each(function(index,el){
			var smallFeedTotal=$("[uniqueid='"+uniqueidStr+"']").find("[name='order_s_small_feed_total']").eq(index).text();
			var feed_total=$("[uniqueid='"+uniqueidStr+"']").find("[name='order_s_material_model']").eq(index).parent().parent().find("[name='order_s_feed_total']").text();
			if(feed_total=="")feed_total=0;
			if(smallFeedTotal!=""){
				feed_total=smallFeedTotal;
			}
			//计算每条料可开数
			menubuttonIndexTool.calResultForMTLKKS(
					$(this).text(),//规格
					$("[uniqueid='"+uniqueidStr+"']").find("[name='order_s_klfs_way']").eq(index).text(),//开料方式
					$("[uniqueid='"+uniqueidStr+"']").find("[name='order_s_klcc_size']").eq(index).text(),//开料尺寸
					materialTypeStr,//物料类型
					$("[uniqueid='"+uniqueidStr+"']").find("[name='order_s_mtlkt_total']").eq(index),//每条料可开数
					$("[uniqueid='"+uniqueidStr+"']").find("[name='order_s_ylts_total']").eq(index),//用料条数
					feed_total//投料数
			);
		})
	},
	//通过  规格型号 开料方式 开料尺寸 和 物料类型计算 每条料可开数
	calResultForMTLKKS:function(modelStr,klWayStr,klSizeStr,materialTypeStr,domOrderSMtlktTotal,domOrderSYltsTotal,feedTotal){
		this.calResultForMTLKKSLog += "原始数据:规格["+modelStr+"]开料方式["+klWayStr+"]开料尺寸["+klSizeStr+"]物料类型["+materialTypeStr+"]\r\n<br>";
		/*清洗数据*/
		//规格
		var modelStrClean=menubuttonIndexTool.onMatch(modelStr,"\\d{0,4}((\\.)?\\d)\\*\\d{1,4}((\\.)?\\d?)\\*\\d{1,4}((\\.)?\\d?)")
		if(modelStrClean.length==0){
			modelStrClean=menubuttonIndexTool.onMatch(modelStr,"\\d{0,4}((\\.)?\\d)\\-\\d{1,4}((\\.)?\\d?)\\-\\d{1,4}((\\.)?\\d?)")
		}
		if(modelStrClean.length==0){
			this.calResultForMTLKKSLog +="<span style='color:red'>错误提示-</span>数据清洗:规格 数据类型不符合 长*宽*高\r\n<br>";
			return;
		}
		//开料尺寸
		var klSizeStrClean=menubuttonIndexTool.onMatch(klSizeStr,"\\d{0,4}((\\.)?\\d)\\*\\d{1,4}((\\.)?\\d?)\\*\\d{1,4}((\\.)?\\d?)")
		if(klSizeStrClean.length==0){
			klSizeStrClean=menubuttonIndexTool.onMatch(klSizeStr,"\\d{0,4}((\\.)?\\d)\\-\\d{1,4}((\\.)?\\d?)\\-\\d{1,4}((\\.)?\\d?)")
		}
		if(klSizeStrClean.length==0){
			this.calResultForMTLKKSLog +="<span style='color:red'>错误提示-</span>数据清洗:开料尺寸 数据类型不符合 长*宽*高\r\n<br>";
			return;
		}
		this.calResultForMTLKKSLog += "数据清洗:规格["+modelStrClean+"]开料方式["+klWayStr+"]开料尺寸["+klSizeStrClean+"]物料类型["+materialTypeStr+"]\r\n<br>";
		var resultTotal="";
		//长度打边
		var dbLength=0;
		//宽度打边
		var dbWidth=0;
		//宽度可减少量	
		var widthCut=0;
		//长度可减少量	
		var lengthCut=0;
		/*ajax 获取 打边 宽度可减少量 长度可减少量*/
		/*ajax 获取 打边 宽度可减少量 长度可减少量*/
		/*ajax 获取 打边 宽度可减少量 长度可减少量*/
		/*ajax 获取 打边 宽度可减少量 长度可减少量*/
		/*ajax 获取 打边 宽度可减少量 长度可减少量*/
    	menubuttonIndexTool.calResultForMTLKKSLog += "工程参数获取中<br>";
		$.ajax({
	        type: 'POST',
	        url: "/weixin/project/getInfo",
	        data: {},
	        async:false,
	        success: function(data){
	        	if(data.data){
	        		widthCut=data.data.widthCut;
	        		lengthCut=data.data.lengthCut;
	        		dbWidth=data.data.widthDb;
	        		dbLength=data.data.lengthDb;
	        	}
	        	menubuttonIndexTool.calResultForMTLKKSLog += "工程参数:长度打边["+dbLength+"]-宽度打边["+dbWidth+"]-长度可减少量["+lengthCut+"]-宽度可减少量["+widthCut+"]<br>";
	    		//物料类型 如果是 肶 打边为0
	    		//if(materialTypeStr.indexOf("肶")>-1)db=0;
	    		menubuttonIndexTool.calResultForMTLKKSLog += "长度打边["+dbLength+"]-宽度打边["+dbWidth+"]-长度可减少量["+lengthCut+"]-宽度可减少量["+widthCut+"]<br>";
	    		//横开
	    		if("横开"==klWayStr){
	    			resultTotal=menubuttonIndexTool.calResultForMTLKKS_x(modelStrClean,klSizeStrClean,materialTypeStr,dbLength,dbWidth,widthCut,lengthCut);
	    		}
	    		//竖开
	    		if("竖开"==klWayStr){
	    			resultTotal=menubuttonIndexTool.calResultForMTLKKS_y(modelStrClean,klSizeStrClean,materialTypeStr,dbLength,dbWidth,widthCut,lengthCut);
	    		}
	    		//双向
	    		if("双向"==klWayStr){
	    			resultTotal=menubuttonIndexTool.calResultForMTLKKS_xy(modelStrClean,klSizeStrClean,materialTypeStr,dbLength,dbWidth,widthCut,lengthCut);
	    		}
	    		//横开
	    		if("横开(不打边)"==klWayStr){
	    			resultTotal=menubuttonIndexTool.calResultForMTLKKS_x(modelStrClean,klSizeStrClean,materialTypeStr,0,0,widthCut,lengthCut);
	    		}
	    		//竖开
	    		if("竖开(不打边)"==klWayStr){
	    			resultTotal=menubuttonIndexTool.calResultForMTLKKS_y(modelStrClean,klSizeStrClean,materialTypeStr,0,0,widthCut,lengthCut);
	    		}
	    		//双向
	    		if("双向(不打边)"==klWayStr){
	    			resultTotal=menubuttonIndexTool.calResultForMTLKKS_xy(modelStrClean,klSizeStrClean,materialTypeStr,0,0,widthCut,lengthCut);
	    		}
	    		if("横开"!=klWayStr&&"竖开"!=klWayStr&&"双向"!=klWayStr&&"横开(不打边)"!=klWayStr&&"竖开(不打边)"!=klWayStr&&"双向(不打边)"!=klWayStr){
	    			menubuttonIndexTool.calResultForMTLKKSLog += "<span style='color:red'>提示:</span>仅针对开料方式[横开][竖开][双向][横开(打边)][竖开(打边)][双向(打边)]<br>";
	    			menubuttonIndexTool.calResultForMTLKKSLog += "------------------------\r\n<br>";
	    			return
	    		}
	    		/*给每条料可开数赋值*/
	    		$(domOrderSMtlktTotal).text(resultTotal);
	    		/*给用料条数赋值*///投料数/每条料可开数取小数两位
	    		menubuttonIndexTool.calResultForMTLKKSLog += "投料数["+feedTotal+"]<br>";
	    		if(resultTotal==0){
	    			$(domOrderSYltsTotal).text(0);
	    		}else{
	    			$(domOrderSYltsTotal).text((feedTotal/resultTotal).toFixed(2));
	    		}
	    		
	    		if(resultTotal==0 || isNaN(resultTotal)){
	    			menubuttonIndexTool.calResultForMTLKKSLog += "<span style='color:red'>错误提示-</span>计算结果错误,请核对规格尺寸和开料尺寸。\r\n<br>";
	    		}
	    		menubuttonIndexTool.calResultForMTLKKSLog += "计算结果["+resultTotal+"]\r\n<br>";
	    		menubuttonIndexTool.calResultForMTLKKSLog += "------------------------\r\n<br>";
	        },
	        dataType: "json"
	     });
	},
	//横开
	calResultForMTLKKS_x:function(modelStrClean,klSizeStrClean,materialTypeStr,dbLength,dbWidth,widthCut,lengthCut){
		//规格长宽高
		var modelStrCleans = (modelStrClean.indexOf("*")>-1?modelStrClean.split("*"):modelStrClean.split("-"));
		var modelLength = modelStrCleans[0];
		var modelWidth = modelStrCleans[1];
		if(modelLength-0<(modelWidth-0)){
			alert("物料规格请按照长*宽*厚度");
			return 0;
		}
		//开料尺寸长宽高
		var klSizeStrCleans = (klSizeStrClean.indexOf("*")>-1?klSizeStrClean.split("*"):klSizeStrClean.split("-"));
		var klSizeLength = klSizeStrCleans[0];
		var klSizeWidth = klSizeStrCleans[1];
		if(klSizeLength-0<(klSizeWidth-0)){
			alert("开料尺寸请按照长*宽*厚度");
			return 0;
		}
		//物料类型 如果是 肶 打边为0
		//if(materialTypeStr.indexOf("肶")>-1)db=0;
		//menubuttonIndexTool.calResultForMTLKKSLog += "工程参数使用:打边["+db+"]-宽度可减少量["+widthCut+"]-长度可减少量["+lengthCut+"]<br>";
		// (规格宽-打边)/(开料尺寸长-长度可减少量)*((规格长-打边)/(开料尺寸宽-宽度可减少量))
		return parseInt((modelWidth-(dbWidth))/(klSizeLength-(lengthCut)))*parseInt((modelLength-(dbLength))/(klSizeWidth-(widthCut)));
	},
	//竖开
	calResultForMTLKKS_y:function(modelStrClean,klSizeStrClean,materialTypeStr,dbLength,dbWidth,widthCut,lengthCut){
		//规格长宽高
		var modelStrCleans = (modelStrClean.indexOf("*")>-1?modelStrClean.split("*"):modelStrClean.split("-"));
		var modelLength = modelStrCleans[0];
		var modelWidth = modelStrCleans[1];
		if(modelLength-0<(modelWidth-0)){
			alert("物料规格请按照长*宽*厚度");
			return 0;
		}
		//开料尺寸长宽高
		var klSizeStrCleans = (klSizeStrClean.indexOf("*")>-1?klSizeStrClean.split("*"):klSizeStrClean.split("-"));
		var klSizeLength = klSizeStrCleans[0];
		var klSizeWidth = klSizeStrCleans[1];
		if(klSizeLength-0<(klSizeWidth-0)){
			alert("开料尺寸请按照长*宽*厚度");
			return 0;
		}
		//物料类型 如果是 肶 打边为0
		//if(materialTypeStr.indexOf("肶")>-1)db=0;
		//menubuttonIndexTool.calResultForMTLKKSLog += "工程参数使用:打边["+db+"]-宽度可减少量["+widthCut+"]-长度可减少量["+lengthCut+"]<br>";
		// (规格宽-打边)/(开料尺寸宽-宽度可减少量)*((规格长-打边)/(开料尺寸长-长度可减少量))
		return parseInt((modelWidth-(dbWidth))/(klSizeWidth-(widthCut)))*parseInt((modelLength-(dbLength))/(klSizeLength-(lengthCut)));
	},
	//双向
	calResultForMTLKKS_xy:function(modelStrClean,klSizeStrClean,materialTypeStr,dbLength,dbWidth,widthCut,lengthCut){
		//规格长宽高
		var modelStrCleans = (modelStrClean.indexOf("*")>-1?modelStrClean.split("*"):modelStrClean.split("-"));
		var modelLength = modelStrCleans[0];
		var modelWidth = modelStrCleans[1];
		//开料尺寸长宽高
		var klSizeStrCleans = (klSizeStrClean.indexOf("*")>-1?klSizeStrClean.split("*"):klSizeStrClean.split("-"));
		var klSizeLength = klSizeStrCleans[0];
		var klSizeWidth = klSizeStrCleans[1];
		//物料类型 如果是 肶 打边为0
		//if(materialTypeStr.indexOf("肶")>-1)db=0;
		//menubuttonIndexTool.calResultForMTLKKSLog += "工程参数使用:打边["+db+"]-宽度可减少量["+widthCut+"]-长度可减少量["+lengthCut+"]<br>";
		//横向开
		var xTotal = this.calResultForMTLKKS_x(modelStrClean,klSizeStrClean,materialTypeStr,dbLength,dbWidth,widthCut,lengthCut);
		//纵向开
		var yTotal = this.calResultForMTLKKS_y(modelStrClean,klSizeStrClean,materialTypeStr,dbLength,dbWidth,widthCut,lengthCut);
		//纵向余数 (规格长-打边)-parseInt((规格长-打边)/(开料尺寸长-长度可减少量)))*(开料尺寸长-长度可减少量)
		var yRate=(modelLength-(dbLength))-parseInt((modelLength-(dbLength))/(klSizeLength-(lengthCut)))*(klSizeLength-(lengthCut));
		//纵项余量可横项数=(纵向余数/(开料尺寸宽-宽度可减少量))*( (规格宽-宽打边)/(开料尺寸长-长度可减少量))
		var yRateTotal = parseInt(yRate/(klSizeWidth-(widthCut)))*parseInt((modelWidth-(dbWidth))/(klSizeLength-(lengthCut)))
		if(xTotal>=(yTotal+yRateTotal)){
			return xTotal;
		}
		return yTotal+yRateTotal;
	},
	//每条可开料数计算小工具
	cal_order_s_mtlkt_total_tool:function(){
		$('div#easyui_dialog_index').dialog({
            modal: false,
            title: '每条可开料数计算小工具',
            width: "550",
            height: "450",
            closed: false,
            border:true,
            cache: false,
            content:"<iframe frameborder='0' scrolling='no' style='width:99%;height:97%;' src='calMTLKKStool.html'></iframe>",
            onClose : function() {  
               $("div#easyui_dialog_index").dialog('destroy');  
               $("body").append("<div id='easyui_dialog_index'></div>");
            }
        });
	}
}
if($("#printArea").length>0)menubuttonIndexTool.initStart();
var str =
	`<span id="menubutton_index">
	<a href="#" id='menubutton_index_tool'>小工具</a>
	<div id="mm1" style="width:150px;">
        <div data-options="iconCls:'icon-save'" onclick="menubuttonIndexTool.saveAsimg()">保存网页为图片</div>
    	<div data-options="iconCls:'icon-ok'" onclick="menubuttonIndexTool.start_interval_saveOrderInfo()">启用实时保存数据</div>
    	<div data-options="iconCls:'icon-cancel'" onclick="menubuttonIndexTool.clear_interval_saveOrderInfo()">禁用实时保存数据</div>
    	<div data-options="iconCls:'icon-reload'" onclick="menubuttonIndexTool.triggle_file_loadOrderInfojson()">载入实时保存数据</div>
    	<div data-options="iconCls:'icon-edit'" onclick="menubuttonIndexTool.fontsizeset()">设置字体大小</div>
    	<div data-options="iconCls:'icon-upload'" onclick="menubuttonIndexTool.uploadOrderFile()">订单附件上传</div>
    	<div data-options="iconCls:'icon-edit'" onclick="menubuttonIndexTool.addMaterialType()" hidden>物料类型添加</div>
    	<div data-options="iconCls:'icon-reload'" onclick="menubuttonIndexTool.refreshMaterialTable()">物料组件刷新</div>
    	<div class="menu-sep"></div>
    	<div>
            <span>制单尺寸选择</span>
            <div>
                <div onclick="menubuttonIndexTool.createOrderSize('a3x')">A3横屏布局</div>
                <div onclick="menubuttonIndexTool.createOrderSize('a3y')">A3竖屏布局</div>
                <div onclick="menubuttonIndexTool.createOrderSize('a4x')">A4横屏布局</div>
                <div onclick="menubuttonIndexTool.createOrderSize('a4y')">A4竖屏布局</div>
            </div>
        </div>
        <div class="menu-sep" ></div>
    	<div >
            <span>物料计算工具</span>
            <div>
                <div onclick="menubuttonIndexTool.cal_order_s_mtlkt_total()">每条可开料数计算</div>
                <div onclick="menubuttonIndexTool.cal_order_s_mtlkt_total_tool()">每条可开料数计算小工具</div>
            </div>
        </div>
        <div class="menu-sep"></div>
    	<div>
            <span>开发者工具</span>
            <div>
                <div onclick="menubuttonIndexTool.clear_Interval_UtilForEveryAreaEvent_allNameReplaceDH()">清除NAME逗号判断</div>
                <div onclick="menubuttonIndexTool.saveTemplateDataAsFileNow()">即刻保存JSON数据</div>
                <div onclick="menubuttonIndexTool.fixcontenxtmenu()">右键位移修正</div>
                <div onclick="menubuttonIndexTool.mydraggablehandler_move()">横向组件无法移动修正</div>
            </div>
        </div>
    </div>
    <input type="file" id="file_loadOrderInfojson" style="display:none" onchange="menubuttonIndexTool.loadOrderInfo();"/>
    </span>`;
/*<div class="menu-sep"></div>
<div>
    <span>业务单工具</span>
    <div>
        <div onclick="menubuttonIndexTool.loadDataFromBusiness()">载入业务单数据</div>
    </div>
</div>*/
$("#menubutton_index").remove();
$("#printArea").parent().append(str)
//流程卡
$("#printAreaCard").parent().append(str)
$('#menubutton_index_tool').menubutton({
    iconCls: 'icon-tip',
    menu: '#mm1'
});
$.getScript("./jquery/html2img/html2cavas.min.js")
.done(function() {
	 $.getScript("./jquery/html2img/canvas2image.js")
	 .done(function() {
		 console.info("html2cavas canvas2image success")
	});
});
//dom 底色白色避免申请 finddff影响
$("[name]").css({"background-color":"white"});
//add printArea Ajax
$("#printArea").bind("click.ajax",function(){
	$.ajax({
        type: 'POST',
        url: serverUrl+"/createOrder/operateLog",
        data: {type:1,order_no:$("[name='order_p_order_no']").val()},
        success: function(data){
          console.info("#printArea operateLog");
        }
	});
})

//校验input 有投料数没有物料信息
function checkFeedTotalHasMaterial(){
	var msg="";
	$("[name='order_s_input_val_feed_total']").parents(".right-div-comp").each(function(){
		if($(this).find("[name='order_s_input_val_feed_total']").val().trim().length>0
				&&
			$(this).find("[name='order_s_input_val_feed_total']").val().trim()!=0){
			if($(this).find("[name='order_s_input_val_material_type']").val().trim().length==0){
				msg+= $(this).find("[name='order_s_input_material_type']").text()+" 物料信息未填写\r\n";
			}
		}
	})
	if(msg.length>0){
		alert(msg);
	}
}
/*键盘按键监听*/
$(document).keyup(function(event){
	console.info(event.keyCode);
	if(event.keyCode==27){
		basic_index.lockTemp(false);
 		basic_index.lockTemp(true);
	}
});
